﻿using System;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;

namespace Be {

    /// <summary>
    /// The class represents a lesson
    /// </summary>
    [DataContract]
    public class BeLesson {

        /// <summary>
        /// Construct the object with different properties.
        /// Used for 
        /// </summary>
        /// <param name="id">The id of the lesson</param>
        /// <param name="start">The starttime of the lesson</param>
        /// <param name="end">The endtime of the lesson</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="comments">The comments</param>
        /// <param name="typeId">The id of the lesson</param>
        public BeLesson(int id, DateTime start, DateTime end, string userId, string comments, int typeId) {
            Id = id;
            StartTime = start;
            EndTime = end;
            UserId = userId;
            Comments = comments;
            TypeId = typeId;
        }

        /// <summary>
        /// Construct the object with different properties.
        /// Used for 
        /// </summary>
        /// <param name="id">The id of the lesson</param>
        /// <param name="starttime">The starttime of the lesson</param>
        /// <param name="endtime">The endtime of the lesson</param>
        /// <param name="comments">The comments</param>
        /// <param name="userId">The id of the user</param>
        public BeLesson(int id, DateTime starttime, DateTime endtime, string comments, string userId) {
            Id = id;
            StartTime = starttime;
            EndTime = endtime;
            Comments = comments;
            UserId = userId;
        }

        /// <summary>
        /// Construct the object with different properties.
        /// Used for 
        /// </summary>
        /// <param name="starttime">The starttime of the lesson</param>
        /// <param name="endtime">The endtime of the lesson</param>
        /// <param name="userId">The id of the user</param>
        /// <param name="comments">The comments</param>
        /// <param name="typeId">The id of the lesson</param>
        public BeLesson(DateTime starttime, DateTime endtime, string userId, string comments, int typeId) {
            StartTime = starttime;
            EndTime = endtime;
            UserId = userId;
            Comments = comments;
            TypeId = typeId;
        }

        /// <summary>
        /// Construct the object with an id and a comment
        /// </summary>
        /// <param name="id">The id of the lesson</param>
        /// <param name="comment">The comment of the lesson</param>
        public BeLesson(int id, string comment) {
            Id = id;
            Comments = comment;
        }

        /// <summary>
        /// Constructs the object with an id.
        /// Used for deleting
        /// </summary>
        /// <param name="id">The id of the lesson</param>
        public BeLesson(int id) {
            Id = id;
        }

        /// <summary>
        /// The id of the lesson
        /// </summary>
        [DataMember]
        public int Id { get; private set; }

        /// <summary>
        /// The starttime of the lesson
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2}-\d{2}-\d{4} \d{2}:\d{2}$")]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// The endtime of the lesson
        /// </summary>
        [DataMember]
        [Required]
        [RegularExpression(@"^\d{2}-\d{2}-\d{4} \d{2}:\d{2}$")]
        public DateTime EndTime { get; set; }

        /// <summary>
        /// The id of the user
        /// </summary>
        [DataMember]
        [Required(AllowEmptyStrings = false)]
        public string UserId { get; private set; }

        /// <summary>
        /// The comments of the lesson
        /// </summary>
        [DataMember]
        public string Comments { get; set; }

        /// <summary>
        /// The type of the lesson
        /// </summary>
        [DataMember]
        [Required]
        public int TypeId { get; private set; }

        /// <summary>
        /// Override the ToString method
        /// </summary>
        /// <returns>The id, starttime and endtime as a string</returns>
        public override string ToString() {
            return "Id's " + Id + " StartTime time: " + StartTime + " EndTime Time: " + EndTime;
        }

        /// <summary>
        /// Check if two lessons are equal
        /// </summary>
        /// <param name="obj">The lesson to check</param>
        /// <returns>True if the two lessons are equal. False otherwise</returns>
        public override bool Equals(object obj) {
            BeLesson lesson = obj as BeLesson;
            if(lesson == null) return false;
            return Id.Equals(lesson.Id);
        }

        /// <summary>
        /// Get the hashcode from the lesson
        /// </summary>
        /// <returns>The hashcode</returns>
        public override int GetHashCode() {
            return Id.GetHashCode();
        }
    }
}